//ps:页面滚动 获取焦点 确定 取消及输入框变化重新调整新闻页面bottom
var newshome="";
if(/news.pulu/.test(location.href)){
    newshome="?newshome";
}
var clinum;//记录点击的第几个按钮控件，防止重复出现
//监听textarea 状态
var newslistbox=$(".wrapper.home_feed")[0];//新闻列表
var callbackinput=$(".callback")[0];//callback评论输入框
var changebottom=95;
var pageSize=10;
$('#commentinput').bind('input propertychange', function(a) {
    if(document.getElementById("commentinput").value){
        if(!/^\s+$/.test(document.getElementById("commentinput").value)){
            $("#sendcommentbtn").attr("class","cmnt_smt");
        }else{
            $("#sendcommentbtn").attr("class","cmnt_smt none_cmnt");
        }
    }else{
        $("#sendcommentbtn").attr("class","cmnt_smt none_cmnt");
    }
});
function getDateTimeStamp(dateStr){
    dateStr=dateStr.replace(/T/g,' ');
    dateStr=dateStr.replace(/\.[0-9]+/g,'');
    return Date.parse(dateStr.replace(/-/gi,"/"));
}
function getDateDiff(dateTimeStamp){
    var minute = 1000 * 60;
    var hour = minute * 60;
    var day = hour * 24;
    var halfamonth = day * 15;
    var month = day * 30;
    var now = new Date().getTime();
    var diffValue = now - dateTimeStamp;
    if(diffValue < 0){return;}
    var monthC =diffValue/month;
    var weekC =diffValue/(7*day);
    var dayC =diffValue/day;
    var hourC =diffValue/hour;
    var minC =diffValue/minute;
    if(monthC>=1){
        result="" + parseInt(monthC) + "月前";
    }
    else if(weekC>=1){
        result="" + parseInt(weekC) + "周前";
    }
    else if(dayC>=1){
        result=""+ parseInt(dayC) +"天前";
    }
    else if(hourC>=1){
        result=""+ parseInt(hourC) +"小时前";
    }
    else if(minC>=1){
        result=""+ parseInt(minC) +"分钟前";
    }else
        result="刚刚";
    return result;
}
var isclicked="no";
//自己的假数据添加回复自己的方法-------------------------------------------------------
/*
 判断是否为PC 改变滚动加载 和头部
 */
var userAgentInfo = navigator.userAgent;
//alert(userAgentInfo);//Mozilla/5.0 (Windows NT 6.1; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0
var Agents = new Array("Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod");
var IsPC="yes";
for (var v = 0; v < Agents.length; v++) {
    if (userAgentInfo.indexOf(Agents[v]) > 0) {
        IsPC="no";
        break;
    }
}
if(IsPC==="yes"){
    if(!/homepc/.test(location.href)){
        location.href="homepc.html"
    }
}
function addothercomjia(e){
    if(e.childNodes[0].id===id){console.log("点的自己")};
    console.log(e);
    document.getElementsByClassName("callback")[0].style.display="block";
    $("#page_wrapper").css("opacity","0");
    location.href="#commentinput";
    document.getElementById("cancelbtn").style.display="block";
    //reid,uid,nickname,liplace
    var reid= e.dataset.id.match(/[0-9]+/)[0];
    var uid=e.dataset.place;
    var nickname= e.dataset.nick;
    var liplace=e.dataset.place;
    $("#commentinput").attr("placeholder","回复 "+nickname+":");
    //取消
    document.getElementById("cancelbtn").onclick=function(){
        console.log("点击了取消1");
        document.getElementsByClassName("callback")[0].style.display="none";
        $("#page_wrapper").css("opacity","1");
        document.getElementById("commentinput").value="";
        reid="";
        liplace="";
        history.go(-1);
        $("#swiper-container").css("display","none");
    };
    //确定
    document.getElementById("sendcommentbtn").onclick=function(){
        if(document.getElementById("commentinput").value&&!document.getElementById("commentinput").value.match(/^\s+$/g)&&isclicked==="no"){
            isclicked="yes";
            var imgs=[];
            var answer={};
            answer.questionId=reid;
            answer.answerUserId=id;
            answer.replyto=uid;
            answer.replytoNick=nickname;
            answer.atype=1;  //评论新闻为1
            answer.up=0;
            answer.down=0;
            answer.content=document.getElementById("commentinput").value;
            var contentcode=answer.content;//保存回复文字 用于插入表情
            $.ajax({
                type:"post",
                datatype:"json",
                url:replyurl,
                data:{"puluanswer":answer,"imgs":imgs},
                success:function(data){
                    //location.reload();//重新加载
                    console.log("评论成功了");
                    var newcontentcode=codetoface(contentcode);//回复文字中插入表情图片
                    isclicked="no";
                    $("#ul"+liplace).append("<li class='listcom' data-place="+liplace+" data-id='c"+data.Data+"' data-nick='"+nickname+"'><span class='commenter'>"+nickname+" 回复 "+nickname+"</span><span>：</span><span >"+newcontentcode+"</span></li>");
                    $("#ul"+liplace).css("display","block");
                    document.getElementsByClassName("callback")[0].style.display="none";
                    $("#page_wrapper").css("opacity","1");
                    $("#swiper-container").css("display","none");
                }
            });
        }else{
            console.log("没有输入内容");
        }
    };
}

var currentIndex=1;
//跳转 历史定位
function gohrefftn(e){
    scrollover=0;
    console.log("保存的地址："+e.dataset.href);
    if(e.dataset.id){
        var neid=e.dataset.id;
        $.ajax({
            type:"post",
            datatype:"json",
            url:addcounturl,
            data:{"newsId":neid},
            success:function(d){
                $.cookie("readyourcurrentIndex",currentIndex);
                //var scrollTop=$(".wrapper.home_feed").scrollTop();
                var scrollTop=$(window).scrollTop();
                if(IsPC=="no"){
                    scrollTop=$(".SimpleToggle.Toggle.HomeMainFeed").scrollTop();
                }
                $.cookie("newstitle","");
                $.cookie("readyourscrollTop",scrollTop);
                $.cookie("newstitle",e.dataset.title);
                $.cookie("newstype",0);
                $.cookie("thumbsUp","");
                location.href="http://www.pulu.com/weixin/newsdetail.html?newsid="+neid+"#fromuser="+id+"#newsShareId="+e.dataset.shareid+"#homepage=1";
            }
        })
    }else{
        $.cookie("readyourcurrentIndex",currentIndex);
        var scrollTop=$(".wrapper.home_feed").scrollTop();
        if(IsPC=="no"){
            scrollTop=$(".SimpleToggle.Toggle.HomeMainFeed").scrollTop();
        }
        $.cookie("readyourscrollTop",scrollTop);
        location.href=e.dataset.href;
    }
}
//删除转发的新闻
var shareid="";
function delmynewsftn(e){
    shareid= e.dataset.shareid;
    $("#delmynews").css("display","block");
}
$("#delmynewsok").click(function(){
    $("#mainp"+shareid).remove();
    $.ajax({
        type:"post",
        data:{"shareId":shareid},
        url:delmynewsurl,
        success:function(d){
            //console.log(d);
            $("#delmynews").css("display","none");
        }
    })
});
$("#delmynewscancel").click(function(){
    shareid="";
    $("#delmynews").css("display","none");
});
//展示加载图片
function showloadimg(e){
    $(e).fadeIn();
}
//
var id;
if($.cookie("MYID")){id=$.cookie("MYID")};

//跳转到新闻列表页面
function gotonewstype(e){
    var newstypeid= e.dataset.ntype;
    $.cookie("newstypeid",newstypeid);
    location.href="http://www.pulu.com/weixin/mycountry.html";
}
//转发新闻 外部链接
$("#addnewsurlbtn").click(function(){
    $("#addnewsurldiv").toggle();
});
$("#shareNewBtn").click(function(){
    //var urlregex = new RegExp("^([hH][tT]{2}[pP]://|[hH][tT]{2}[pP][sS]://|[wW]{3})(([A-Za-z0-9-~]+).)+([A-Za-z0-9-~])+");
    var urlregex = new RegExp("^(([hH][tT]{2}[pP]://|[hH][tT]{2}[pP][sS]://)(([A-Za-z0-9-~]+))|([wW]{3}).)+([A-Za-z0-9-~])+");
    if(urlregex.test($("#inputnewsurl").val()))
    {
        $.ajax({
            type:"post",
            url:shareoutnewsurl,
            data:{"url":$("#inputnewsurl").val(),"userId": $.cookie("MYID")},
            success:function(d){
                location.reload();
            }
        })
    }
})
//微信所有方法------------------------------
function allftn(){
    var id;
    if(!$.cookie("MYID")){
        if(/\?id=[0-9a-zA-Z]+/.test(location.href)){
            id=(location.href).match(/id=[0-9a-zA-Z]+/)[0].split("=")[1];
            $.cookie("MYID",id);
        }else{
            location.href="http://www.pulu.com/weixin/login.html"+newshome;
        }
    }
    else if($.cookie("MYID")!="undefined"){
        id=$.cookie("MYID");
    }else{
        location.href="http://www.pulu.com/weixin/login.html"+newshome;
    };
    var headphotobtn=document.getElementsByClassName("photo");
    for(var i2=0;i2<headphotobtn.length;i2++){
        headphotobtn[i2].index=i2;
        headphotobtn[i2].onclick=function(){
            location.href="otherpeoplepage.html?otherid="+headphotobtn[this.index].id;
        }
    }
////////////////////////////////////////////////////////////
    var nick="";
    $().ready(function(){
        var clinum="";//记录点击的第几个按钮控件，防止重复出现
        $.ajax({
            type:"post",
            url:userurl,
            data:{"userId":id},
            success:function(d){
                nick= d.Data.userNick;
            }
        });
        if($.cookie("readyourcurrentIndex")){
            //console.log($.cookie("readyourcurrentIndex"));//===================有问题============================
            currentIndex=$.cookie("readyourcurrentIndex");
            var allnum=parseFloat($.cookie("readyourcurrentIndex"))*parseFloat(pageSize);
            ajget(1,allnum);
        }else{
            ajget(currentIndex,pageSize);
        }
    });
    var scrollover=1;//页面滚动是否结束 1结束了
    var upanddown=127;
    //页面滚动加载 只有PC才有效
    $(window).scroll(function(){
        //电脑才有滚动
        if(IsPC==="yes"){
            var mainheight=$("#page_wrapper").height();
            var windowheight=$(window).height();
            var what=$("#page_wrapper").offset().top;
            var chajuli=$("#page_wrapper").offset().top-$(window).scrollTop();
            var cz=windowheight-mainheight+100;
            if(chajuli<cz&&scrollover===1){
                scrollover=0;
                currentIndex++;
                ajget(currentIndex,pageSize);
            }
            //导航条隐藏显示
            //var a2=chajuli;
            //if(a2<upanddown){
            //    upanddown=a2;
            //    //向下滚动
            //    if(chajuli<-44){
            //        $(".fixed_header").css({"position":"fixed","top":"-44px"});
            //    }
            //}
            //else{
            //    upanddown=a2;
            //    //向上滚动
            //    if(-44<chajuli){
            //        $(".fixed_header").css({"position":"absolute","top":"0px"});
            //    }
            //}
        }
    });
    var a3=0;//保存上一次滑动
    //新闻滑动
    $(".SimpleToggle.Toggle.HomeMainFeed").scroll(function(){
        //移动设备
        if(IsPC==="no"){
            var screenH=window.screen.height;//屏幕高度
            //var windowheight=window.screen.availHeight;
            var mainheight=$(".SimpleToggle.Toggle.HomeMainFeed>div").height();//加载区内主体高度
            var scrollH=$(".SimpleToggle.Toggle.HomeMainFeed").scrollTop();//加载区内滚动隐藏高度
            var rangeH=scrollH+screenH+80;//范围
            if(mainheight<rangeH&&scrollover===1){
                scrollover=0;
                currentIndex++;
                ajget(currentIndex,pageSize);
            }
            //导航条隐藏显示
            //var a2=scrollH;//当前滑动
            //if(a2>a3){  //向下滑动
            //    a3=a2;//保存当前距离
            //    if(scrollH>=44){
            //        //.wrapper.home_feed
            //        //$(".SimpleToggle.Toggle.HomeMainFeed").css("margin-top","44px");
            //        //$(".SimpleToggle.Toggle.HomeMainFeed").css("padding-top","80px");
            //        $(".wrapper.home_feed>div").css("margin-top","40px");
            //        $(".wrapper.home_feed>div").css("height",window.screen.height-40+"px");
            //        $(".SimpleToggle.Toggle.HomeMainFeed").css("padding-top","44px");
            //        $("#zhzx").css("padding-top","44px");
            //        $("#hyxw").css("padding-top","44px");
            //        $("#xq").css("padding-top","44px");
            //        $(".Header .fixed_header").css("top","-44px");
            //        $(".Header .fixed_header").css("position","fixed");
            //    }
            //}
            //else if(a2<a3)//向上滑动
            //{
            //    a3=a2;//保存当前距离
            //    if(scrollH<44){
            //        //console.log("小于88");
            //        //$(".SimpleToggle.Toggle.HomeMainFeed").css("margin-top","127px");
            //        $(".wrapper.home_feed>div").css("margin-top","83px");
            //        $(".wrapper.home_feed>div").css("height",window.screen.height-83+"px");
            //        $(".SimpleToggle.Toggle.HomeMainFeed").css("padding-top","0");
            //        $("#zhzx").css("padding-top","0");
            //        $("#hyxw").css("padding-top","0");
            //        $("#xq").css("padding-top","0");
            //        $(".Header .fixed_header").css("top","0");
            //        $(".Header .fixed_header").css("position","absolute");
            //    }
            //}

        }
    });
    //综合资讯滑动
    $("#zhzx").scroll(function(){
        //移动设备
        if(IsPC==="no"){
            var screenH=window.screen.height;//屏幕高度
            var mainheight=$("#listplace").height();//加载区内主体高度
            var scrollH=$("#zhzx").scrollTop();//加载区内滚动隐藏高度
            var rangeH=scrollH+screenH+80;//范围
            //导航条隐藏显示
            //var a2=scrollH;//当前滑动
            //if(a2>a3){  //向下滑动
            //    a3=a2;//保存当前距离
            //    if(scrollH>=44){
            //        $(".wrapper.home_feed>div").css("margin-top","40px");
            //        $(".wrapper.home_feed>div").css("height",window.screen.height-40+"px");
            //        $(".SimpleToggle.Toggle.HomeMainFeed").css("padding-top","44px");
            //        $("#zhzx").css("padding-top","44px");
            //        $("#hyxw").css("padding-top","44px");
            //        $("#xq").css("padding-top","44px");
            //        $(".Header .fixed_header").css("top","-44px");
            //        $(".Header .fixed_header").css("position","fixed");
            //    }
            //}else if(a2<a3){  //向上滑动
            //    a3=a2;//保存当前距离
            //    if(scrollH<44){
            //        $(".wrapper.home_feed>div").css("margin-top","83px");
            //        $(".wrapper.home_feed>div").css("height",window.screen.height-83+"px");
            //        $(".SimpleToggle.Toggle.HomeMainFeed").css("padding-top","0");
            //        $("#zhzx").css("padding-top","0");
            //        $("#hyxw").css("padding-top","0");
            //        $("#xq").css("padding-top","0");
            //        $(".Header .fixed_header").css("top","0");
            //        $(".Header .fixed_header").css("position","absolute");
            //    }
            //}
        }
    });
    //行业新闻滑动
    $("#hyxw").scroll(function(){
        //移动设备
        if(IsPC==="no"){
            var screenH=window.screen.height;//屏幕高度
            var mainheight=$("#hylistplace").height();//加载区内主体高度
            var scrollH=$("#hyxw").scrollTop();//加载区内滚动隐藏高度
            var rangeH=scrollH+screenH+80;//范围
            //导航条隐藏显示
            //var a2=scrollH;//当前滑动
            //if(a2>a3){  //向下滑动
            //    a3=a2;//保存当前距离
            //    if(scrollH>=44){
            //        $(".wrapper.home_feed>div").css("margin-top","40px");
            //        $(".wrapper.home_feed>div").css("height",window.screen.height-40+"px");
            //        $(".SimpleToggle.Toggle.HomeMainFeed").css("padding-top","44px");
            //        $("#zhzx").css("padding-top","44px");
            //        $("#hyxw").css("padding-top","44px");
            //        $("#xq").css("padding-top","44px");
            //        $(".Header .fixed_header").css("top","-44px");
            //        $(".Header .fixed_header").css("position","fixed");
            //    }
            //}else if(a2<a3){  //向上滑动
            //    a3=a2;//保存当前距离
            //    if(scrollH<44){
            //        $(".wrapper.home_feed>div").css("margin-top","83px");
            //        $(".wrapper.home_feed>div").css("height",window.screen.height-83+"px");
            //        $(".SimpleToggle.Toggle.HomeMainFeed").css("padding-top","0");
            //        $("#zhzx").css("padding-top","0");
            //        $("#hyxw").css("padding-top","0");
            //        $("#xq").css("padding-top","0");
            //        $(".Header .fixed_header").css("top","0");
            //        $(".Header .fixed_header").css("position","absolute");
            //    }
            //}
        }
    });
    //兴趣爱好滑动
    $("#xq").scroll(function(){
        //移动设备
        if(IsPC==="no"){
            var screenH=window.screen.height;//屏幕高度
            var mainheight=$("#xqlistplace").height();//加载区内主体高度
            var scrollH=$("#xq").scrollTop();//加载区内滚动隐藏高度
            var rangeH=scrollH+screenH+80;//范围
            //导航条隐藏显示
            //var a2=scrollH;//当前滑动
            //if(a2>a3){  //向下滑动
            //    a3=a2;//保存当前距离
            //    if(scrollH>=44){
            //        $(".wrapper.home_feed>div").css("margin-top","40px");
            //        $(".wrapper.home_feed>div").css("height",window.screen.height-40+"px");
            //        $(".SimpleToggle.Toggle.HomeMainFeed").css("padding-top","44px");
            //        $("#zhzx").css("padding-top","44px");
            //        $("#hyxw").css("padding-top","44px");
            //        $("#xq").css("padding-top","44px");
            //        $(".Header .fixed_header").css("top","-44px");
            //        $(".Header .fixed_header").css("position","fixed");
            //    }
            //}else if(a2<a3){  //向上滑动
            //    a3=a2;//保存当前距离
            //    if(scrollH<44){
            //        $(".wrapper.home_feed>div").css("margin-top","83px");
            //        $(".wrapper.home_feed>div").css("height",window.screen.height-83+"px");
            //        $(".SimpleToggle.Toggle.HomeMainFeed").css("padding-top","0");
            //        $("#zhzx").css("padding-top","0");
            //        $("#hyxw").css("padding-top","0");
            //        $("#xq").css("padding-top","0");
            //        $(".Header .fixed_header").css("top","0");
            //        $(".Header .fixed_header").css("position","absolute");
            //    }
            //}
        }
    });
    //加载主页内容
    function ajget(currentIndex,pageSize){
        var changeimg=false;//是否加载第一张图状态
        $.ajax({
            type:"get",
            datatype:"json",
            url:readyoursurl+id+"&pageSize="+pageSize+"&currentIndex="+currentIndex,
            //url:readyoursurl+id+"&pageSize=1&currentIndex="+currentIndex,
            success:function(data){
                var alldata=data;
                var fortim=0;//记录for循环次数 是否循环结束
                if(data.Data&&data.Data.length>0){
                    if(data.Data.length<pageSize){
                        $("#waiting").remove();
                        $("#nonews").css("display","block");
                    }
                    for(var i1=0;i1<data.Data.length;i1++){
                        fortim++;
                        var me=i1;//保存对应位置

                        //用户有头像
                        var uimgword="";
                        if(data.Data[i1].userAva){
                            uimgword="<img onclick='gohrefftn(this)' data-href='otherpeoplepage.html?otherid="+data.Data[i1].userId+"' class='profile_photo_img' src='http://42.62.66.198:8003/"+data.Data[i1].userAva+"' onload='showloadimg(this)' style='display:none;'>";
                        }else{
                            uimgword="<img onclick='gohrefftn(this)' data-href='otherpeoplepage.html?otherid="+data.Data[i1].userId+"' class='profile_photo_img' src='../img/af8.png' onload='showloadimg(this)' style='display:none;'>";}
                        // 用户有昵称
                        var unick="";
                        if(data.Data[i1].nick&&data.Data[i1].nick.length>0){unick=data.Data[i1].nick;}
                        //用户转发新闻有自己的评论
                        var uview="";
                        if(data.Data[i1].des){
                            var newcontentcode=codetoface(data.Data[i1].des);//文字中插入表情图片
                            uview="<div class='info_wrapper senderview'><div class='info'><span class='feed_item_answer_user'>"+newcontentcode+"</span></div></div>"
                        }
                        //时间
                        var datatime="";
                        if(data.Data[i1].shareTime){datatime=getDateDiff(getDateTimeStamp(data.Data[i1].shareTime));}
                        if(!datatime||datatime=="undefined"){datatime="刚刚"};
                        //是否为自己的新闻
                        var mynews="";
                        if(data.Data[i1].userId==id){mynews="<div class='delnews' onclick='delmynewsftn(this)' data-shareid='"+data.Data[i1].shareId+"'>删除</div>";}
                        //新闻是否有评论  是否有点赞
                        var ncom="";
                        var haveheart="";//是否点赞过 修改class
                        var haveheartname="赞";//是否点赞过 修改名称
                        if((data.Data[i1].puluNewsAnswerExt&&data.Data[i1].puluNewsAnswerExt.length>0)||(data.Data[i1].ShareNewsUpList&&data.Data[i1].ShareNewsUpList.length>0)){
                            var tim=0;
                            //评论
                            if(data.Data[i1].puluNewsAnswerExt&&data.Data[i1].puluNewsAnswerExt.length>0){
                                for(var r1=0;r1<data.Data[i1].puluNewsAnswerExt.length;r1++){
                                    tim++;
                                    ////获取有评论新闻的评论序号 对应ul的位置
                                    data.Data[i1].puluNewsAnswerExt[r1].index=r1;
                                    ////回复有评论
                                    var replyname="";
                                    if(data.Data[i1].puluNewsAnswerExt[r1].toUserName){replyname=" 回复 "+data.Data[i1].puluNewsAnswerExt[r1].toUserName;}
                                    var newcontentcode=codetoface(data.Data[i1].puluNewsAnswerExt[r1].answerContent);//文字中插入表情图片
                                    ncom+="<li class='listcom' data-place='"+data.Data[i1].shareId+"' data-id='c"+data.Data[i1].puluNewsAnswerExt[r1].questionId+"' data-nick='"+data.Data[i1].puluNewsAnswerExt[r1].userName+"'><span class='commenter' id='"+data.Data[i1].puluNewsAnswerExt[r1].answerUserId+"'>"+data.Data[i1].puluNewsAnswerExt[r1].userName+replyname+"</span><span>：</span><span >"+newcontentcode+"</span></li>";
                                }
                            }
                            //点赞
                            var goodlist="";
                            if(data.Data[i1].ShareNewsUpList&&data.Data[i1].ShareNewsUpList.length>0){

                                for(var a=0;a<data.Data[i1].ShareNewsUpList.length;a++){
                                    //是否已经点过赞了
                                    if(data.Data[i1].ShareNewsUpList[a].userId==id){
                                        haveheartname="取消";
                                    }
                                    goodlist+="<span class='heartspan' data-uid='"+data.Data[i1].ShareNewsUpList[a].userId+"'>"+data.Data[i1].ShareNewsUpList[a].userNick+"</span>&nbsp;&nbsp;"
                                }
                                //goodlist=goodlist.substring(0,goodlist.length-1);
                                goodlist="<li class='heartli' id='li"+data.Data[i1].shareId+"' style='display:block;'><span class='heartplacelogo'></span>"+goodlist+"</li>";
                            }else{
                                goodlist="<li class='heartli' id='li"+data.Data[i1].shareId+"' style='display:none;'><span class='heartplacelogo'></span></li>";
                            }
                            //修改添加
                            ncom="<ul class='commentplace' id='ul"+data.Data[i1].shareId+"'><li class='toparrow'></li> "+goodlist+ncom+"</ul>";
                        }
                        //系统推荐
                        var disp="";//display
                        var palf="";//padding-left
                        if(data.Data[i1].istopnews===1){
                            palf="style='padding-left:0;'";
                            disp="style='display:none;'";
                            unick="<i onclick='gotonewstype(this)' data-ntype='"+data.Data[i1].typeid+"'>最新"+data.Data[i1].newsTypeName+"资讯·"+data.Data[i1].sitename+"</i>";
                        }
                        //推荐
                        var tuijian="";
                        if(data.Data[i1].isStranger===1||data.Data[i1].istopnews===1){
                            tuijian="<div class='addfriend "+data.Data[i1].userId+"' "+disp+" onclick='addfriend(this)' data-uid='"+data.Data[i1].userId+"'>+加好友</div><div class='tuijian'></div>";}
                        var typeneme="【"+data.Data[i1].newsTypeName+"】";
                        if(data.Data[i1].typeid==202){typeneme=""};//转发网址 外部
                        //新闻有图片
                        var imgword="";
                        var haveimgtype=false;//是否有图片
                        if(data.Data[i1].thumb){    //href='"+data.Data[i1].url+"'
                            haveimgtype=true;
                            //默认老样式 没有图片样式可用
                            imgword="<div class='feed_answer_preview answer_content'><a onclick='gohrefftn(this)' data-href='"+data.Data[i1].url+"' data-id='"+data.Data[i1].id+"' data-title='"+data.Data[i1].title+"' data-shareid='"+data.Data[i1].shareId+"'><div class='truncated_thumbnail_holder'><span class='rendered_qtext'><div class='qtext_image_wrapper'><canvas class='qtext_image_placeholder landscape qtext_image zoomable_in_feed' width='500' height='500' style='visibility: hidden;'></canvas><img class='landscape qtext_image zoomable_in_feed lazy_loaded lazy_loading' src='"+data.Data[i1].thumb+"'onload='showloadimg(this)' style='display:none;'></div></span></div></a></div>";}
                        if(haveimgtype){//如果有图片
                            if(changeimg){//已经加载完 使用新样式
                                imgword="<div class='feed_answer_preview answer_content'><h2 class='no_highlight'><a class='question_link hrefto' onclick='gohrefftn(this)' data-id='"+data.Data[i1].id+"' data-href='"+data.Data[i1].url+"' data-title='"+data.Data[i1].title+"' data-shareid='"+data.Data[i1].shareId+"'><span class='question_text'><span class='rendered_qtext'>"+typeneme+data.Data[i1].title+"</span></span></a></h2><a onclick='gohrefftn(this)' data-href='"+data.Data[i1].url+"' data-id='"+data.Data[i1].id+"' data-title='"+data.Data[i1].title+"' data-shareid='"+data.Data[i1].shareId+"'><div class='truncated_thumbnail_holder'><span class='rendered_qtext'><div class='qtext_image_wrapper'><canvas class='qtext_image_placeholder landscape qtext_image zoomable_in_feed' width='500' height='500' style='visibility: hidden;'></canvas><img class='landscape qtext_image zoomable_in_feed lazy_loaded lazy_loading' src='"+data.Data[i1].thumb+"' onload='showloadimg(this)' style='display:none;'></div></span></div></a></div>";
                                $(".HomeMainFeed>div.newsbody").append("<div class='pagedlist_item' id='mainp"+data.Data[i1].shareId+"'> <div class='feed_item feed_type_answer'>"+tuijian+"<div class='ContentHeader'> <div class='photo_info_layout size_small'> <div class='photo_wrapper' "+disp+"> <div class='photo'> "+ uimgword+" </div> </div> <div class='info_wrapper' "+palf+"> <span class='feed_item_answer_user'> <span class='user'>"+unick+"</span><span class='sign'></span> </span> <div class='ContentFooter'>"+datatime+"</div> </div> </div> </div> "+uview+"<div class='Answer'><div class='QuestionAnswerVerbose SimpleToggle Toggle' id='main"+data.Data[i1].shareId+"'>"+imgword+"<div class='ActionBar'><div class='action_bar_inner' "+disp+"><div class='action_item'><a class='ReadMoreActionItem eyesbox'><span class='answer_count' >"+data.Data[i1].count+"</span></a></div>"+mynews+"<div class='overflow action_item overflow_link' data-id='"+data.Data[i1].shareId+"'><a class='overflow_link' data-id='"+data.Data[i1].shareId+"'><span class='dots overflow_dots' data-id='"+data.Data[i1].shareId+"'></span></a></div><div class='actionlist' id='actionlist"+data.Data[i1].shareId+"'><div class='collectbtn "+haveheart+"' id='coll"+data.Data[i1].shareId+"'>"+haveheartname+"</div><div id='newsid"+data.Data[i1].id+"' data-shareid='"+data.Data[i1].shareId+"' class='addnewscom'>评论</div></div></div></div>"+ncom+"</div></div></div></div>");}
                            else{//没有加载第一张图 使用老样式
                                changeimg=true;
                                $(".HomeMainFeed>div.newsbody").append("<div class='pagedlist_item' id='mainp"+data.Data[i1].shareId+"'> <div class='feed_item feed_type_answer'>"+tuijian+"<div class='ContentHeader'> <div class='photo_info_layout size_small'> <div class='photo_wrapper' "+disp+"> <div class='photo'> "+ uimgword+" </div> </div> <div class='info_wrapper' "+palf+"> <span class='feed_item_answer_user'> <span class='user'>"+unick+"</span><span class='sign'></span> </span> <div class='ContentFooter'>"+datatime+"</div> </div> </div> </div> "+uview+"<h2 class='no_highlight'><a class='question_link hrefto' onclick='gohrefftn(this)' data-id='"+data.Data[i1].id+"' data-href='"+data.Data[i1].url+"' data-title='"+data.Data[i1].title+"' data-shareid='"+data.Data[i1].shareId+"'><span class='question_text'><span class='rendered_qtext'>"+typeneme+data.Data[i1].title+"</span></span></a></h2><div class='Answer'><div class='QuestionAnswerVerbose SimpleToggle Toggle' id='main"+data.Data[i1].shareId+"'>"+imgword+"<div class='ActionBar'><div class='action_bar_inner' "+disp+"><div class='action_item'><a class='ReadMoreActionItem eyesbox'><span class='answer_count' >"+data.Data[i1].count+"</span></a></div>"+mynews+"<div class='overflow action_item overflow_link' data-id='"+data.Data[i1].shareId+"'><a class='overflow_link' data-id='"+data.Data[i1].shareId+"'><span class='dots overflow_dots' data-id='"+data.Data[i1].shareId+"'></span></a></div><div class='actionlist' id='actionlist"+data.Data[i1].shareId+"'><div class='collectbtn "+haveheart+"' id='coll"+data.Data[i1].shareId+"'>"+haveheartname+"</div><div id='newsid"+data.Data[i1].id+"' data-shareid='"+data.Data[i1].shareId+"' class='addnewscom'>评论</div></div></div></div>"+ncom+"</div></div></div></div>");}
                        }else{//没有图片 全部使用老的样式
                            $(".HomeMainFeed>div.newsbody").append("<div class='pagedlist_item' id='mainp"+data.Data[i1].shareId+"'> <div class='feed_item feed_type_answer'>"+tuijian+"<div class='ContentHeader'> <div class='photo_info_layout size_small'> <div class='photo_wrapper' "+disp+"> <div class='photo'> "+ uimgword+" </div> </div> <div class='info_wrapper' "+palf+"> <span class='feed_item_answer_user'> <span class='user'>"+unick+"</span><span class='sign'></span> </span> <div class='ContentFooter'>"+datatime+"</div> </div> </div> </div> "+uview+"<h2 class='no_highlight'><a class='question_link hrefto' onclick='gohrefftn(this)' data-id='"+data.Data[i1].id+"' data-href='"+data.Data[i1].url+"' data-title='"+data.Data[i1].title+"' data-shareid='"+data.Data[i1].shareId+"'><span class='question_text'><span class='rendered_qtext'>"+typeneme+data.Data[i1].title+"</span></span></a></h2><div class='Answer'><div class='QuestionAnswerVerbose SimpleToggle Toggle' id='main"+data.Data[i1].shareId+"'>"+imgword+"<div class='ActionBar'><div class='action_bar_inner' "+disp+"><div class='action_item'><a class='ReadMoreActionItem eyesbox'><span class='answer_count' >"+data.Data[i1].count+"</span></a></div>"+mynews+"<div class='overflow action_item overflow_link' data-id='"+data.Data[i1].shareId+"'><a class='overflow_link' data-id='"+data.Data[i1].shareId+"'><span class='dots overflow_dots' data-id='"+data.Data[i1].shareId+"'></span></a></div><div class='actionlist' id='actionlist"+data.Data[i1].shareId+"'><div class='collectbtn "+haveheart+"' id='coll"+data.Data[i1].shareId+"'>"+haveheartname+"</div><div id='newsid"+data.Data[i1].id+"' data-shareid='"+data.Data[i1].shareId+"' class='addnewscom'>评论</div></div></div></div>"+ncom+"</div></div></div></div>")
                        }
                        //展示网站公司信息
                        $("#footer").css("display","block");
                        var addnewscom=document.getElementsByClassName("addnewscom");   //评论按钮
                        for(var r2=0;r2<addnewscom.length;r2++){
                            var anid="";
                            var shareId="";
                            addnewscom[r2].index=r2;
                            addnewscom[r2].onclick=function(){
                                anid=(addnewscom[this.index].id).match(/[0-9]+/)[0];
                                shareId=parseFloat(addnewscom[this.index].dataset.shareid);
                                $("#commentinput").attr("placeholder","");
                                document.getElementsByClassName("callback")[0].style.display="block";
                                $("#page_wrapper").css("opacity","0");
                                location.href="#commentinput";
                                $("#commentinput").focus();
                                sendcom(anid,shareId);
                            }
                        }
                        var listcom=document.getElementsByClassName("listcom");    //每一条评论
                        for(var r3=0;r3<listcom.length;r3++){
                            var reid="";
                            var nickname="";
                            var liplace="";
                            listcom[r3].index=r3;
                            listcom[r3].onclick=function(){
                                if(listcom[this.index].className==="listcom"){
                                    reid=(listcom[this.index].dataset.id).match(/[0-9]+/)[0];
                                    nickname=listcom[this.index].dataset.nick;
                                    liplace=listcom[this.index].dataset.place;  //用于添加评论假数据查找li所在的ul的位置
                                    var uid=listcom[this.index].childNodes.item(0).id;
                                    //不是回复自己
                                    if(nickname!== $.cookie("MYNICK")){
                                        document.getElementsByClassName("callback")[0].style.display="block";
                                        $("#page_wrapper").css("opacity","0");
                                        location.href="#commentinput";
                                        $("#commentinput").focus();
                                        addothercom(reid,uid,nickname,liplace);
                                    }
                                }
                            }
                        }
                        var collectbtn=document.getElementsByClassName("collectbtn"); //赞
                        for(var r4=0;r4<collectbtn.length;r4++){
                            var collectid="";
                            collectbtn[r4].index=r4;
                            collectbtn[r4].onclick=function(){
                                collectid=(collectbtn[this.index].id).match(/[0-9]+/)[0];
                                //console.log(id);
                                //console.log(collectbtn[this.index].innerHTML);

                            }
                        }
                        //分享新闻 提问 模态框
                        var overflowlist=document.getElementsByClassName("overflow");
                        var actionlist=document.getElementsByClassName("actionlist");
                        for(var i3=0;i3<overflowlist.length;i3++){
                            overflowlist[i3].index=i3;
                            overflowlist[i3].onclick=function(e){
                                if(clinum){console.log(clinum)}
                                //console.log(e.target);
                                var aid=e.target.dataset.id;
                                //console.log(aid);
                                //========================================

                                if(clinum&&clinum==aid){ //当前按钮已经点击
                                    //console.log(clinum); this.index.toString()
                                    //console.log("已存在");
                                    //actionlist[this.index].className="actionlist displaied2";
                                    $("#actionlist"+aid).attr("class","actionlist displaied2");
                                    clinum="";
                                }else if(clinum&&clinum!=aid){//其他按钮已经点击了
                                    //actionlist[clinum].className="actionlist displaied2";//关闭其他按钮
                                    //actionlist[this.index].className="actionlist displaied1";//展开当前按钮
                                    $("#actionlist"+clinum).attr("class","actionlist displaied2");//关闭其他按钮
                                    $("#actionlist"+aid).attr("class","actionlist displaied1");//展开当前按钮
                                    clinum=aid;//更改当前记录数字
                                }else{//第一次点击
                                    //console.log("第一次点击的位置",$("#actionlist"+aid));
                                    //actionlist[this.index].className="actionlist displaied1";//展开当前按钮
                                    $("#actionlist"+aid).attr("class","actionlist displaied1");//展开当前按钮
                                    clinum=aid;//更改当前记录数字 wz位置
                                }
                                //========================================
                            }
                        };
                        //点击屏幕实现弹框隐藏 &&与||
                        var bigbody=document.getElementById("page_wrapper");
                        bigbody.onclick=function(e){
                            for(var i=0;i<actionlist.length;i++){
                                if(actionlist[i].className=="actionlist displaied1"){
                                    if(e.target.className!=="overflow_link"&&e.target.className!=="dots overflow_dots"&&e.target.className!=="callback"){
                                        actionlist[i].className="actionlist displaied2";
                                        clinum="";
                                    }
                                }
                            }
                        };
                        scrollover=1;//滚动结束了
                    };
                    //定位滚动跳转
                    if($.cookie("readyourscrollTop")){
                        var t=parseFloat($.cookie("readyourscrollTop"));
                        console.log(t);
                        console.log(IsPC);
                        //$(".wrapper.home_feed").scrollTop(t);
                        if(IsPC==="no"){
                            //$(".showlist00").scrollTop(t);
                            $(".SimpleToggle.Toggle.HomeMainFeed").scrollTop(t);
                        }else{$(window).scrollTop(t);}
                        $.cookie("readyourcurrentIndex","");
                        $.cookie("readyourscrollTop","");
                    }
                }else{
                    scrollover=0;
                    $("#waiting").remove();
                    $("#nonews").css("display","block");
                }
            }
        });
    };
    /*
     *
     * 加载新闻列表
     *
     */
    if(IsPC==="no"){
        if(!$.cookie("zhzx")){
            //综合资讯
            $.ajax({
                type:"get",
                datatype:"json",
                url:zonghenewsurl+190+"&userId="+id,//api/typeinfo/GetSecondTypeByParentId?parentId=
                success:function(data){
                    //cookie保存数据
                    var arr=[];
                    for(var i=0;i<data.Data.length;i++){
                        //<span class='tc_unread'>
                        arr.push(data.Data[i].id+data.Data[i].typename);
                        $("#listbox").append("<li class='Cell' id="+data.Data[i].id+"><div class='tc_image'><img src='hyimg/"+data.Data[i].id+".png' class='topic_photo_img'/></div><span class='tc_inner' id='zh"+data.Data[i].id+"'><span class='tc_text'>"+data.Data[i].typename+"</span></span></span><div class='tc_stroke'></div></li>")
                    }
                    var expireDate = new Date();
                    expireDate.setTime( expireDate.getTime() + ( 24*60*60 * 1000 ) );
                    arr=arr.join(",");
                    $.cookie('zhzx',arr,{
                        expires :expireDate
                    });
                }
            });
            //行业新闻
            $.ajax({
                type:"get",
                datatype:"json",
                url:zonghenewsurl+191+"&userId="+id,//api/typeinfo/GetSecondTypeByParentId?parentId=
                success:function(data){
                    //cookie保存数据
                    var arr=[];
                    for(var i=0;i<data.Data.length;i++){
                        arr.push(data.Data[i].id+data.Data[i].typename);
                        $("#hylistbox").append("<li class='Cell' id="+data.Data[i].id+"><div class='tc_image'><img src='hyimg/"+data.Data[i].id+".png' class='topic_photo_img'/></div><span class='tc_inner'id='zh"+data.Data[i].id+"'><span class='tc_text'>"+data.Data[i].typename+"</span></span><div class='tc_stroke'></div></li>")
                    }
                    var expireDate = new Date();
                    expireDate.setTime( expireDate.getTime() + ( 24*60*60 * 1000 ) );
                    arr=arr.join(",");
                    $.cookie('hyxw',arr,{
                        expires :expireDate
                    });
                }
            });
            //兴趣爱好
            $.ajax({
                type:"get",
                datatype:"json",
                url:zonghenewsurl+192+"&userId="+id,
                success:function(data){
                    //cookie保存数据
                    var arr=[];
                    for(var i=0;i<data.Data.length;i++){
                        arr.push(data.Data[i].id+data.Data[i].typename);
                        $("#xqlistbox").append("<li class='Cell' id="+data.Data[i].id+"><div class='tc_image'><img src='hyimg/"+data.Data[i].id+".png' class='topic_photo_img'/></div><span class='tc_inner'id='zh"+data.Data[i].id+"'><span class='tc_text'>"+data.Data[i].typename+"</span></span><div class='tc_stroke'></div></li>")
                    }
                    var expireDate = new Date();
                    expireDate.setTime( expireDate.getTime() + ( 24*60*60 * 1000 ) );
                    arr=arr.join(",");
                    $.cookie('xqah',arr,{
                        expires :expireDate
                    });
                }
            });
        }
        else{
            //综合资讯
            //var data1=$.cookie("zhzx").slice(0,-1);
            var data1=$.cookie("zhzx").split(",");
            for(var i=0;i<data1.length;i++){
                var dataid=data1[i].match(/[0-9]+/)[0];
                var dataname=data1[i].replace(/[0-9]+/,"");
                $("#listbox").append("<li class='Cell' id="+dataid+"><div class='tc_image'><img src='hyimg/"+dataid+".png' class='topic_photo_img'/></div><span class='tc_inner' id='zh"+dataid+"'><span class='tc_text'>"+dataname+"</span></span></span><div class='tc_stroke'></div></li>")
            }
            //行业新闻
            //var data2=$.cookie("hyxw").slice(0,-1);
            var data2=$.cookie("hyxw").split(",");
            for(var i=0;i<data2.length;i++){
                var dataid=data2[i].match(/[0-9]+/)[0];
                var dataname=data2[i].replace(/[0-9]+/,"");
                $("#hylistbox").append("<li class='Cell' id="+dataid+"><div class='tc_image'><img src='hyimg/"+dataid+".png' class='topic_photo_img'/></div><span class='tc_inner' id='zh"+dataid+"'><span class='tc_text'>"+dataname+"</span></span></span><div class='tc_stroke'></div></li>")
            }
            //兴趣爱好
            //var data3=$.cookie("xqah").slice(0,-1);
            var data3=$.cookie("xqah").split(",");
            for(var i=0;i<data3.length;i++){
                var dataid=data3[i].match(/[0-9]+/)[0];
                var dataname=data3[i].replace(/[0-9]+/,"");
                $("#xqlistbox").append("<li class='Cell' id="+dataid+"><div class='tc_image'><img src='hyimg/"+dataid+".png' class='topic_photo_img'/></div><span class='tc_inner' id='zh"+dataid+"'><span class='tc_text'>"+dataname+"</span></span></span><div class='tc_stroke'></div></li>")
            }
        };
        $("#zhzx").delegate("li.Cell","click",function(e){
            var eventnode= e.target;
            var tpid=0;
            var nameword="";
            if(eventnode.className=="tc_text"){
                tpid=eventnode.parentNode.parentNode.id;
                nameword=eventnode.innerHTML;
            }else if(eventnode.className=="tc_inner"){
                tpid=eventnode.parentNode.id;
                nameword=eventnode.firstChild.innerHTML;
            }
            $.cookie("currentIndex","");
            $.cookie("scrollTop","");
            $.cookie("newsid","");
            $.cookie("totop","");
            //直接页面跳转
            $.cookie("newstypeid",tpid);
            $.cookie("newstypename",nameword);
            if($("#zhzx").css("display")==="block"){
                //返回页面参数
                $.cookie("newstype",1);
                if($.cookie("newstypeid")&&$.cookie("newstypename")){
                    location.href="http://www.pulu.com/weixin/mycountry.html?from=zonghe";
                }
            }
        });
        $("#hyxw").delegate("li.Cell","click",function(e){
            var eventnode= e.target;
            var tpid=0;
            var nameword="";
            if(eventnode.className=="tc_text"){
                tpid=eventnode.parentNode.parentNode.id;
                nameword=eventnode.innerHTML;
            }else if(eventnode.className=="tc_inner"){
                tpid=eventnode.parentNode.id;
                nameword=eventnode.firstChild.innerHTML;
            }
            $.cookie("currentIndex","");
            $.cookie("scrollTop","");
            $.cookie("newsid","");
            $.cookie("totop","");
            //直接页面跳转
            $.cookie("newstypeid",tpid);
            $.cookie("newstypename",nameword);
            if($("#hyxw").css("display")==="block"){
                //返回页面参数
                $.cookie("newstype",2);
                if($.cookie("newstypeid")&&$.cookie("newstypename")){
                    location.href="mycountry.html?from=hangye";
                }

            }
        });
        $("#xq").delegate("li.Cell","click",function(e){
            var eventnode= e.target;
            var tpid=0;
            var nameword="";
            if(eventnode.className=="tc_text"){
                tpid=eventnode.parentNode.parentNode.id;
                nameword=eventnode.innerHTML;
            }else if(eventnode.className=="tc_inner"){
                tpid=eventnode.parentNode.id;
                nameword=eventnode.firstChild.innerHTML;
            }
            $.cookie("currentIndex","");
            $.cookie("scrollTop","");
            $.cookie("newsid","");
            $.cookie("totop","");
            //直接页面跳转
            $.cookie("newstypeid",tpid);
            $.cookie("newstypename",nameword);
            if($("#xq").css("display")==="block"){
                //返回页面参数
                $.cookie("newstype",3);
                if($.cookie("newstypeid")&&$.cookie("newstypename")){
                    location.href="mycountry.html?from=xingqu";
                }
            }
        });
    }
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------
    //--------------------------------------------------------------------------------------------------
//添加评论按钮
    function sendcom(anid,shareId){
        console.log("dianji");
        //取消按钮点击
        document.getElementById("cancelbtn").onclick=function(){
            document.getElementsByClassName("callback")[0].style.display="none";
            $("#page_wrapper").css("opacity","1");
            document.getElementById("commentinput").value="";
            anid="";
            shareId="";
            $("#swiper-container").css("display","none");
            $("#commentinput").attr("placeholder","回复:");
            history.go(-1);
            $("#sendcommentbtn").attr("class","cmnt_smt none_cmnt");
        };
        //确定按钮点击
        document.getElementById("sendcommentbtn").onclick=function(){
            if(document.getElementById("commentinput").value&&!document.getElementById("commentinput").value.match(/^\s+$/g)&&isclicked==="no"){
                isclicked="yes";
                var imgs=[];
                var answer={};
                answer.questionId=anid;
                answer.answerUserId=id;
                answer.atype=1;  //评论新闻为1
                answer.isShare=1;
                answer.shareId=shareId;
                answer.up=0;
                answer.down=0;
                answer.content=document.getElementById("commentinput").value;
                var contentcode=answer.content;//保存回复文字 用于插入表情
                $.ajax({
                    type:"post",
                    datatype:"json",
                    url:replyurl,
                    data:{"puluanswer":answer,"imgs":imgs},
                    success:function(data){
                        var newcontentcode=codetoface(contentcode);//回复文字中插入表情图片
                        isclicked="no";
                        document.getElementById("commentinput").value="";
                        // 重新加载
                        history.go(-1);//url hash修改
                        $("#ul"+shareId).css("display","block");
                        if($("#ul"+shareId+" li")&&$("#ul"+shareId+" li").length>0){
                            $("#ul"+shareId).append("<li class='listcom' data-place="+shareId+" data-id='c"+data.Data+"' data-nick='"+$.cookie("MYNICK")+"'><span class='commenter' id="+id+">"+$.cookie("MYNICK")+"</span><span>：</span><span >"+newcontentcode+"</span></li>")
                        }else{
                            //
                            $("#main"+shareId).append("<ul class='commentplace' id='ul"+shareId+"'><li class='toparrow'></li><li class='heartli' id='li"+shareId+"' style='display:none;'><span class='heartplacelogo'></span></li><li class='listcom'  data-place="+shareId+" data-id='c"+data.Data+"' data-nick='"+$.cookie("MYNICK")+"'><span class='commenter' id="+id+">"+$.cookie("MYNICK")+"</span><span>：</span><span >"+newcontentcode+"</span></li></ul>")
                        }
                        document.getElementsByClassName("callback")[0].style.display="none";
                        $("#page_wrapper").css("opacity","1");
                        $("#commentinput").attr("placeholder","回复:");
                        $("#sendcommentbtn").attr("class","cmnt_smt none_cmnt");
                        $("#swiper-container").css("display","none");
                    }
                });
            }else{
                console.log("没有输入内容");
            }
        };
    };
//回复他人评论
    function addothercom(reid,uid,nickname,liplace){
        $("#commentinput").attr("placeholder","回复 "+nickname+":");
        document.getElementById("cancelbtn").onclick=function(){
            document.getElementsByClassName("callback")[0].style.display="none";
            $("#page_wrapper").css("opacity","1");
            document.getElementById("commentinput").value="";
            reid="";
            liplace="";
            $("#swiper-container").css("display","none");
            history.go(-1);
            $("#sendcommentbtn").attr("class","cmnt_smt none_cmnt");
            $("#swiper-container").css("display","none");
        };
        document.getElementById("sendcommentbtn").onclick=function(){
            if(document.getElementById("commentinput").value&&!document.getElementById("commentinput").value.match(/^\s+$/g)&&isclicked==="no"){
                isclicked="yes";
                var imgs=[];
                var answer={};
                answer.questionId=reid;
                answer.answerUserId=id;
                answer.replyto=uid;
                answer.replytoNick=nickname;
                answer.atype=1;  //评论新闻为1
                answer.shareId=liplace;
                answer.isShare=1;
                answer.up=0;
                answer.down=0;
                answer.content=document.getElementById("commentinput").value;
                var contentcode=answer.content;//保存回复文字 用于插入表情
                $.ajax({
                    type:"post",
                    datatype:"json",
                    url:replyurl,
                    data:{"puluanswer":answer,"imgs":imgs},
                    success:function(data){
                        var newcontentcode=codetoface(contentcode);//回复文字中插入表情图片
                        isclicked="no";
                        document.getElementById("commentinput").value="";
                        history.go(-1);//url hash修改
                        $("#ul"+liplace).append("<li class='listcom' data-place="+liplace+" data-id='c"+data.Data+"' data-nick='"+$.cookie("MYNICK")+"'><span class='commenter' id="+id+">"+ $.cookie("MYNICK")+" 回复 "+nickname+"</span><span>：</span><span>"+newcontentcode+"</span></li>");
                        document.getElementsByClassName("callback")[0].style.display="none";
                        $("#page_wrapper").css("opacity","1");
                        $("#commentinput").attr("placeholder","回复:");
                        $("#sendcommentbtn").attr("class","cmnt_smt none_cmnt");
                        $("#swiper-container").css("display","none");
                    }
                });
            }else{
                console.log("没有输入内容");
            }
        };
    };
//刷新页面
    $("#refreshbtn").click(function(){
        currentIndex=1;
        $(".wrapper.home_feed>div").css("margin-top","127px");
        $(".wrapper.home_feed>div").css("height",window.screen.height-127+"px");
        $(".SimpleToggle.Toggle.HomeMainFeed").css("padding-top","0");
        $(".Header .fixed_header").css("top","0");
        $(".HomeMainFeed div.newsbody div").remove();
        ajget(currentIndex,pageSize);
    });
}
var returnurl=encodeURIComponent("http://www.pulu.com/weixin/home.html"); //同意后跳转页面
$(document).ready(function(){
    if(is_weixn()){
        if($.cookie("wxopenid")){
            //从登录页返回有openid没有id
            if($.cookie("MYID")){allftn();}
            else{location.href="http://www.pulu.com/weixin/login.html"+newshome;}
        }
        else{
            //先微信验证获取openid 如果已经授权过了 直接页面截取openid 然后发送请求获取 用户的ID
            var reg=new RegExp("code=[a-zA-Z0-9]*");
            if(window.location.href.match(reg)){
                var code=window.location.href.match(reg);
                $.ajax({
                    type:"GET",
                    url:"GetOpenId.ashx?"+code,
                    async: false,
                    success:function(data){
                        console.log(data);
                        var dat=data;
                        $.cookie("wxod",dat);
                        //发请求获取用户的id
                        $.ajax({
                            type:"GET",
                            url:getwxopenidurl+dat,
                            success:function(d){
                                console.log(d);
                                //如果没有用户id 则证明用户是第一次登陆 保存openid跳转至登录页面
                                if(!d.Data){
                                    //微信跳转进来的
                                    if(!$.cookie("MYID")){
                                        $.cookie("wxopenid",dat);
                                        location.href="http://www.pulu.com/weixin/login.html"+newshome;
                                    }
                                    //退出登录的
                                }else if(d.Data&&d.Data.userId.length>0){
                                    $.cookie("wxopenid",d.Data.openId);
                                    $.cookie("MYID",d.Data.userId);
                                    $.cookie("MYAVA",d.Data.userAva);
                                    $.cookie("MYNICK",d.Data.userNick);
                                    id=d.Data.userId;
                                    allftn();
                                }
                            }
                        })
                    }
                })
            }
            else{
                location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx658c34793ecfd9f9&redirect_uri="+returnurl+"&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
            }
        }
    }
    else{
        allftn();
    }
});
//环信建立连接
var conn = new WebIM.connection({
    https: WebIM.config.https,
    url: WebIM.config.xmppURL,
    isAutoLogin: WebIM.config.isAutoLogin,
    isMultiLoginSessions: WebIM.config.isMultiLoginSessions
});
//登录
var options = {
    apiUrl: WebIM.config.apiURL,
    user:id,
    pwd:id,
    appKey: "pulu#pulu"
};
conn.open(options);
//加好友
function addfriend(e){
    //console.log(e.dataset.uid);
    if(!/clicked/.test(e.className)){
        //$("."+e.dataset.uid).attr("css","addfriend clicked "+e.dataset.uid);
        e.className+=" clicked";
        //e.innerHTML="已添加";
        conn.subscribe({
            to: e.dataset.uid,
            message: ""
        });
    }
}
if( ("onhashchange" in window) && ((typeof document.documentMode==="undefined") || document.documentMode==8)) {
    //浏览器支持onhashchange事件
    window.onhashchange = hashChangeFire;
}
else { // 不支持则用定时器检测的办法
    setInterval(function() {
        var ischanged = isHashChanged();
        if(ischanged) {
            hashChangeFire();
        }
    }, 150);
};
function hashChangeFire(){
    if(!/commentinput/.test(location.href)){
        $(".cmnt_fixed.callback").css("display","none");
        $("#page_wrapper").css("opacity","1");
    }
};